﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Runtime.Serialization.Json;

namespace EGov
{
    public partial class frmtinmoi : PhoneApplicationPage
    {
        List<Place> ListTinTuc= new List<Place>();
        public frmtinmoi()
        {            
            InitializeComponent();

            string tinmoi = "http://egov047.juddy.vn/api/place";
            WebClient client = new WebClient();
            client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
            client.OpenReadAsync(new Uri(tinmoi), UriKind.Absolute);
        }
        void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            try
            {
                var ser = new DataContractJsonSerializer(typeof(List<Place>), null);
                ListTinTuc = (List<Place>)ser.ReadObject(e.Result);
                foreach (var item in ListTinTuc)
                    if (item.Image == null)
                        item.Image = "http://egov047.juddy.vn/_serviceData/Images/77.jpg";
                this.lstListTin.ItemsSource = ListTinTuc;
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public static string idtin;
        private void Image_DoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            try
            {
                Place f = lstListTin.SelectedItem as Place;
                idtin = f.Id;
                NavigationService.Navigate(new Uri("/chitiettintuc2.xaml?selectedItem=" + f.Id , UriKind.Relative));
                //changeflag = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
      
    }
}